$(function() {
    $("#sub").click(function () {
        var userName=$("#user").val();
        var password=$("#passwd").val();
        var password2=$("#confi").val();
        var email=$("#mail").val();
        var jiaoyan=$("#pattern").val();
        var jiaoyanNew=jiaoyan.trim();
        var patern1=/^\w{5,12}/;
        if(!patern1.test(userName)){
            $("span").text("用户名不合法");
            return false;
        }else{
            $("span").text("");
        }
        if(!patern1.test(password)){
            $("span").text("密码不合法");
            return false;
        }else{
            $("span").text("");
        }
        if(password2!=password){
            $("span").text("两次输入的密码不相同");
            return false;
        }else{
            $("span").text("");
        }
        if(email.indexOf('@')==-1||email.indexOf(".com")==-1){
            $("span").text("邮箱不合法");
            return false;
        }else{
            $("span").text("");
        }
        if(jiaoyanNew==null||jiaoyanNew==""){
            $("span").text("验证码为空");
            return false;
        }else{
            $("span").text("");
        }
    });
    $("#yanzheng").click(function(){
        this.src="../kaptcha?time="+new Date();
    });
    $("#changea").click(function () {
        $("#yanzheng").attr("src","../kaptcha?time="+new Date());
        return false;
    });
    $("#user").blur(function() {
        $.get("../action","action=confirmUserName&name="+this.value,function(data) {
            $("#span2").text(data);
        },"text");
    });
});